import {category} from '../../../models/explore'
let givCategory= new category()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    fileList: [],
    list:[
     "色情低估",
     "政治敏感",
     "违法犯罪",
     "垃圾广告",
     "涉嫌诈骗",
     "非原创内容",
     "其他"
    ],
    data:{
      momentId:'',
      receiptPics:[],
      reportReason:[],
      reportReasonDetail:''
    },
    contentText:'',
    result: [],
    id:''
  },

  onChange(event) {
    
    this.setData({
      result: event.detail,
    });
    this.data.data.reportReason=this.data.result
    console.log(this.data.data.reportReason)
  },
  toggle(event) {
    const { index } = event.currentTarget.dataset;
    const checkbox = this.selectComponent(`.checkboxes-${index}`);
    checkbox.toggle();
  },
  noop() {},
  // 点击确认
  confirm(){
    this.setData({ show: false });
  },
// 点击取消
  cancel(){
    this.setData({ show: false });
  },
  // 提交
  get(){
    if (!this.data.contentText) {
      wx.showToast({
        title: '请输入举报用户的原因'
      })
      return
    }
    var receiptPics=[]
    this.data.fileList.map(item=>{
      receiptPics.push(item.url)
    })
    console.log(receiptPics)
    givCategory.noGetCategory({
      momentId:this.data.id,
      reportReason:this.data.result.join(","),
      receiptPics,
      reportReasonDetail:this.data.contentText
    },res=>{
      wx.showToast({
            title:res
          })
    })
  },

// 上传图片
  afterRead:function(event) {
    let that=this
    const { file } = event.detail;
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    wx.uploadFile({
      url: 'http://192.168.0.195:8291/OnLoad/uploadFile', 
      filePath: file.url,
      method:'POST',
      name: 'file',
      mutiple:true,
      formData: { user: 'test' },
      success(res) {
        // 上传完成需要更新 fileList
        const { fileList = [] } = that.data;
        console.log(res.data, 'datatatata')
        res.data = JSON.parse(res.data).data
        fileList.push({ ...file, url: res.data });
        that.setData({ fileList });
  },
    });
  },
  // 删除图片
  text(event){
   console.log(event);
  },
  showPopup(e) {
    console.log(e)
    this.setData({ show: true });
  },

  onClose() {
    this.setData({ show: false });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(this.data.contentText.length);
    this.data.id=options.id
    this.data.momentId=options.id
    console.log(options)
  },
  deletePic(e) {
    console.log(e, 'deletePic')
    const that=this
    let fileList=this.data.fileList
    let index=e.detail.index
    wx.showModal({
      title: '提示',
      content: '确认要删除该图片吗?',
      success: function (res) {
        if (res.confirm) {
          fileList.splice(index,1)
        } else if (res.cancel) {
          return false
        }
        that.setData({
          fileList
        })
      }
    })
  }
})